package top.kaoshanji.p3ch11a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * 代码清单-p3ch11a-348页a：通过join方法等待线程运行结束
 * author kaoshanji
 * ^_^
 * create time 2025/2/4 10:02
 */
public class ThreadJoin {

    private static final Logger logger = LogManager.getLogger(ThreadJoin.class);

    public static void main(String[] args) {
        logger.info("...代码清单-p3ch11a-348页a：通过join方法等待线程运行结束...");

        ThreadJoin join = new ThreadJoin();
        join.useJoin();

    }

    public void useJoin() {
        Thread thread = new Thread() {

            @Override
            public void run() {
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };

        thread.start();
        // 执行其他操作
        System.out.println("START");
        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("END");
    }


}
